package anet

import (
	"fmt"

	"gitee.com/AlexWoo/arpc"
)

var (
	ePool = arpc.NewPool(func() any { return &event{} })
)

func getEvent(name string, typ eventType, sid uint64) *event {
	ev := ePool.Get().(*event)

	ev.name = name
	ev.typ = typ
	ev.sid = sid

	return ev
}

func putEvent(ev *event) {
	ePool.Put(ev)
}

type eventType uint8

const (
	eventType_connected eventType = iota
	eventType_sessTimeout
	eventType_recvTimeout
	eventType_sendTimeout
	eventType_max
)

var eventTypeEnum = []string{
	"connected",
	"sessTimeout",
	"recvTimeout",
	"sendTimeout",
}

func (et eventType) String() string {
	if et >= eventType_max {
		return "unknown"
	}

	return eventTypeEnum[et]
}

type event struct {
	name string
	typ  eventType
	sid  uint64
}

func (ev *event) String() string {
	return fmt.Sprintf("%s %s %d", ev.name, ev.typ, ev.sid)
}
